# 修改wos的bib
import os
import sys
from util import read_file,write_file
def str_2_bib_format(bib_content_str):
    bib_content_str = bib_content_str.split(',')
    # bib_content_str[1] = "\n"+bib_content_str[1]
    # bib_content_str[1] = "\n"+bib_content_str[1]
    bib_content_str = ",".join(bib_content_str)
    # bib_content_str = bib_content_str.replace("},", "},\n")
    bib_format_text = bib_content_str+"\n"
    return bib_format_text

def bib_item_str(bib_content_str):
    bib_content_list = bib_content_str.split('\n\n')
    for i in range(len(bib_content_list)):
        bib_content_list[i] = bib_content_list[i].strip("\n")
    return bib_content_list
    
if __name__ == '__main__':
    wos_bib_file_name = "active_planning_nearst_5_year.bib"
    new_bib_file_name = "active_planning_nearst_5_year_new_change.bib"
    project_path = os.path.join(os.path.dirname(__file__),'..')
    bib_file_folder = os.path.join(project_path,'bib_file')
    wos_bib_file_path= os.path.join(bib_file_folder,'ori_bib',wos_bib_file_name)
    new_bib_file_path= os.path.join(bib_file_folder,'updata_bib',new_bib_file_name)
    bib_content_all_str = read_file(wos_bib_file_path)
    bib_content_list = bib_item_str(bib_content_all_str)
    for i in range(len(bib_content_list)):
        bib_content_list[i] = str_2_bib_format(bib_content_list[i])
    write_file(new_bib_file_path, bib_content_list)
